package 剑指offer;

import noffer.base.TreeNode;

/**
 * @author zhangjunfei
 * @date 2023/8/25 11:18
 */
public class O_26 {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if (B == null || A == null) {
            return false;
        }
        return recur(A,B) || isSubStructure(A.left, B) || isSubStructure(A.right, B);

    }

    boolean recur(TreeNode a, TreeNode b) {
        if (b == null) {
            return true;
        }
        if (a == null || a.val != b.val) {
            return false;
        }
        return recur(a.left, b.left) && recur(a.right, b.right);
    }
}
